using B.S.RbacData.Infrastructure;
using ContentmanagementBase.Infrastructure;
using ContentmanagementBaseRead.API.AutomapperFiles;
using Microsoft.EntityFrameworkCore;
using NLog.Web;
using System.Reflection;

namespace ContentmanagementBaseRead.API
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.
            //ע�����ݿ�������
            builder.Services.AddDbContext<ContentManagementDBContext>(x =>
            {
                x.UseMySql(builder.Configuration.GetConnectionString("mysql"), new MySqlServerVersion("5.7"));
            });
            //ע��Nlog
            builder.Host.UseNLog();
            //ע���н���ģʽ
            builder.Services.AddMediatR(x => x.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
            //ע��ִ�
            builder.Services.AddScoped(typeof(IBaseRepository<>), typeof(BaseRepository<>));
            //ע���Զ�ӳ��
            builder.Services.AddAutoMapper(typeof(AutomapperProFiles));

            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            //����Swaggerע��
            builder.Services.AddSwaggerGen(o =>
            {
                //��ȡ��Ŀ����
                var projectName =typeof(Program).Assembly.GetName().Name;
                
                var path =AppDomain.CurrentDomain.BaseDirectory+ projectName+".xml";

                o.IncludeXmlComments(path,true);
            });

            var app = builder.Build();
            //����
            app.UseCors(x => x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}
